import {
    Toast
  } from "vant";
  import cTitle from "components/title";
  import {
    scrollMixin
  } from "../../../utils/mixin";
  export default {
    mixins: [scrollMixin], //加载更多
    data() {
      return {
        tabsList: [
            '直推用户',
            '团队用户'
        ],
        currentTabs: 0,//0直推 1团队用户
        countNum: 0,
        list: [
          // {
          //   nickname: '1111',
          //   num: '1',
          //   vip: '普通用户',
          //   mobile: '15584451495',
          //   create_at: '2024-12-16 10:22:21',
          //   rensu: '1',
          //   yeji: '200'
          // }
        ],
        text: '',
        // page: 1,//分页 当前页数
        // pageCount: 1,//分页  总页数
        isLoadMore: true,
        page: 1,
        total_page: 0,
        zhituiNum: 0,//直推用户数量
        teamNum: 0,//团队人数
        departmentPeople: 0,//部门人数
        departmentNum: 0,//部门业绩
        sdepartmentNum: 0,//小部门业绩
        userName: '',
      };
    },
  
    components: {
      cTitle
    },
    filters: {
      formatPhoneNumber(phoneNumber) {
        // 检查手机号长度是否为11位，如果不是则直接返回原字符串（或者你可以抛出错误）
        if (phoneNumber.length !== 11 || isNaN(phoneNumber)) {
            return phoneNumber; // 或者 throw new Error('Invalid phone number');
        }
        
        if (phoneNumber.length !== 11 || isNaN(phoneNumber)) {
          if (phoneNumber == '') {
            return ''; // 或者 throw new Error('Invalid phone number');
          }else {
            return phoneNumber; // 或者 throw new Error('Invalid phone number');
          }
          
        }
        
        // 使用slice()方法提取手机号的前3位和后4位，中间用'XXXX'替换
        return phoneNumber.slice(0, 2) + '*******' + phoneNumber.slice(9);
     }
    },
    // mounted() {
    //   if (!localStorage.getItem("uid")) {
    //     this.$router.push(this.fun.getUrl("member"));
    //     return
    //   }
    //   this.getList();
    // },
    activated() {
      this.list = [];
      this.page = 1;
      if (!localStorage.getItem("uid")) {
        this.$router.push(this.fun.getUrl("member"));
        return
      }
      this.getList();
    },
    computed: {
  
    },
    methods: {
        changeTabs(index){
            this.currentTabs = index;
            // this.getList();
        },
      openPicker() {
        this.pickerShow = true;
      },
      search(){
        this.page = 1;
        this.list = [];
        this.getList();
      },
      getList() {
        $http.get("NiuTwo.web_team", {
          uid: localStorage.getItem("uid"),
          page: this.page,
          text: this.userName,
        }, "加载中").then((res) => {
          if (res.result == 1) {
            console.log(res, 'shuju_list')
            
            this.departmentPeople = res.data.all_ren ? res.data.all_ren : 0;//部门人数
            this.departmentNum = res.data.sum ? res.data.sum : 0;//部门业绩
            this.sdepartmentNum = res.data.min ? res.data.min : 0;//小部门业绩
            var nextPageData = res.data.list.data;
            this.list = [...this.list, ...nextPageData];
            this.total_page = res.data.list.last_page;
            this.isLoadMore = true;
  
          } else {
            this.isLoadMore = false;
          }
        });
      },
      getMoreData() {
        if (!this.isLoadMore) return;
        this.isLoadMore = false; // 防止多次请求分页数据
        if (this.page >= this.total_page) {
          Toast('已加载全部数据')
          return;
        } else {
          this.page += 1;
          this.getList();
        }
      },
      
    }
  };